package com.daoxu.util;

import com.daoxu.api.APIService;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 林强 on 17/3/30.
 */
public class RetrofitUtil {

    /**
     * 服务器地址
     */
    private static final String API_HOST = "http://120.77.34.102:8080";

    /**
     * 豆瓣服务器地址
     */
    //private static final String API_HOST = "https://api.douban.com";

    private static APIService service;
    private static Retrofit retrofit;

    public static APIService getService() {
        if (service == null) {
            service = getRetrofit().create(APIService.class);
        }
        return service;
    }

    private static Retrofit getRetrofit() {
        if (retrofit == null) {
            OkHttpClient client = new OkHttpClient.Builder()
                    .build();
            retrofit = new Retrofit.Builder()
                    .client(client)
                    .baseUrl(API_HOST)
                    .addConverterFactory(GsonConverterFactory.create())//使用Gson
                    .build();
        }
        return retrofit;
    }



}
